﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PerformanceTest
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RaisingStudio.Data.Providers.DataContext dc = new RaisingStudio.Data.Providers.DataContext();
            var connection = dc.Connection;
            int count = 1000;
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                var command = connection.CreateCommand();
                command.CommandText = "select count(*) from DAC_USER where USERNAME = @UserName";
                var parameter = command.CreateParameter();
                parameter.ParameterName = "@UserName";
                parameter.DbType = DbType.String;
                parameter.Value = "a";
                command.Parameters.Add(parameter);

                var value = RaisingStudio.Data.Common.Database.ExecuteScalarCommand(command);
                //Console.WriteLine(value);
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds + "ms");            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            RaisingStudio.Data.Providers.DataContext dc = new RaisingStudio.Data.Providers.DataContext();
            var connection = dc.Connection;
            int count = 1000;

                var command = connection.CreateCommand();
                command.CommandText = "select count(*) from DAC_USER where USERNAME = @UserName";
                var parameter = command.CreateParameter();
                parameter.ParameterName = "@UserName";
                parameter.DbType = DbType.String;
                parameter.Value = "a";
                command.Parameters.Add(parameter);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            for (int i = 0; i < count; i++)
            {

                var value = RaisingStudio.Data.Common.Database.ExecuteScalarCommand(command);
                //Console.WriteLine(value);
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds + "ms");
        }
    }
}
